package com.hzeng.util;


public class Program {
	final static String delimiter = " | ";
	final static double oneM = 1024 * 1024;
	final static double oneK = 1024;
	
	private long pid;
	private String name;
	private String directoryName;
	private double cpu;
	private double memory;
	private double virtualMemory;
	private double totalMemory;
	private double read;
	private double write;
	private long timestamp;
	private String bin;
	private long readBytes;
	private long writeBytes;
	
	
	public long getReadBytes() {
		return readBytes;
	}
	public void setReadBytes(long readBytes) {
		this.readBytes = readBytes;
	}
	public long getWriteBytes() {
		return writeBytes;
	}
	public void setWriteBytes(long writeBytes) {
		this.writeBytes = writeBytes;
	}
	public String getBin() {
		return bin;
	}
	public void setBin(String bin) {
		this.bin = bin;
	}
	public double getTotalMemory() {
		return totalMemory;
	}
	public void setTotalMemory(double totalMemory) {
		this.totalMemory = totalMemory;
	}
	public long getTimestamp() {
		return timestamp;
	}
	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}
	public double getVirtualMemory() {
		return virtualMemory;
	}
	public void setVirtualMemory(double virtualMemory) {
		this.virtualMemory = virtualMemory;
	}
	public long getPid() {
		return pid;
	}
	public void setPid(long pid) {
		this.pid = pid;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDirectoryName() {
		return directoryName;
	}
	public void setDirectoryName(String directoryName) {
		this.directoryName = directoryName;
	}
	public double getCpu() {
		return cpu;
	}
	public void setCpu(double cpu) {
		this.cpu = cpu;
	}
	public double getMemory() {
		return memory;
	}
	public void setMemory(double memory) {
		this.memory = memory;
	}
	public double getRead() {
		return read;
	}
	public void setRead(double read) {
		this.read = read;
	}
	public double getWrite() {
		return write;
	}
	public void setWrite(double write) {
		this.write = write;
	}
	
	public String[] toSimpleArray() {
		return new String[]{name,pid + "",formatMemory(memory),formatCPU(cpu)};
	}
	
	public String toSimpleString() {
		return name + delimiter + pid + delimiter + formatMemory(memory) + formatCPU(cpu);
	}
	
	public String toRecordString() {
		return name + delimiter + pid + delimiter + cpu + delimiter + memory + delimiter + virtualMemory;
	}
	
	public String formatCPU(double cpu) {
		if (cpu > 1) {
			
		}else if(cpu > 0) {
			cpu = cpu * 100;
		}else {
			cpu = 0;
		}
		return cpu + "";
	}
	
	public String formatMemory(double memory) {
		if(memory > oneM) {
			memory = memory / oneM;
			return memory + "M";
		}else if (memory > oneK) {
			memory = memory / oneK;
			return memory + "K";
		}
		return memory + "";
	}
}
